<?php
include('../includes/common.php');
if ($islogin != 1) {
	exit('<script language=\'javascript\'>window.location.href=\'./login.php\';</script>');
}
?>

<?php
$title = '记录日志';
include('head.php');
?>
<section id="main-content">
    <section class="wrapper">
        <div class="modal fade" align="left" id="search" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="modal-title" id="myModalLabel">搜索记录</h4>
                    </div>
                    <div class="modal-body">
                        <input type="text" class="form-control" name="kw" placeholder="请输入记录"><br />
                        <button type="button" class="btn btn-primary btn-block" id="search_submit">搜索</button>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>

        <?php
        if ($my == 'delete') {
            $id = $_GET['id'];
            $rs = $conn->query("select * from rmb_list where id='$id'");
            if ($rs->num_rows == 0) {
                showmsg('当前记录不存在！', 3);
            } else {
                $rs = $conn->query("delete from rmb_list where id='$id'");
                if ($rs) {
                    showmsg('删除成功！<br/><br/><a href="./safelist.php">>>返回记录列表</a>', 1);
                } else {
                    showmsg('删除失败！', 4);
                }
            }
        } else {
            ?>
            <div class="row">
                <div class="col-lg-12">
                    <section class="panel">
                        <header class="panel-heading">
                            <div class="btn-group">
                                <a class="btn btn-warning" href="#" data-toggle="dropdown">
                                    操作
                                    <i class="icon-angle-down "></i>
                                </a>
                                <ul class="dropdown-menu">

                                    <li><a href="#" onclick="datadel()"><i class="icon-trash"></i>删除</a></li>
                                </ul>
                            </div>
                            <a href="javascript:listTable('start')" class="btn btn-default" title="刷新记录列表"><i class="fa fa-refresh"></i></a>
                        </header>
                        <div id="listTable"></div>
                    </section>
                </div>
            </div>
        <?php
        }
        ?>
    </section>
</section>
<script>
    function listTable(query) {
        var url = window.document.location.href.toString();
        var queryString = url.split("?")[1];
        query = query || queryString;
        if (query == 'start' || query == undefined) {
            query = '';
            history.replaceState({}, null, './moneylist.php');
        } else if (query != undefined) {
            history.replaceState({}, null, './moneylist.php?' + query);
        }
        layer.closeAll();
        var ii = layer.load(2, {
            shade: [0.1, '#fff']
        });
        $.ajax({
            type: 'GET',
            url: 'moneylist-table.php?' + query,
            dataType: 'html',
            cache: false,
            success: function(data) {
                layer.close(ii);
                $("#listTable").html(data)
            },
            error: function(data) {
                layer.msg('服务器错误');
                return false;
            }
        });
    }

    function datadel() {
        layer.confirm('您确定要删除这些记录吗？<br>不会影响对应宿舍舍费', {
            btn: ['确定', '取消']
        }, function() {
            var cks = document.getElementsByName("checkid");
            var str = "";
            for (var i = 0; i < cks.length; i++) {
                if (cks[i].checked) {
                    str += cks[i].value + "&";
                }
            }
            str = str.substring(0, str.length - 1);
            $.ajax({
                url: "ajax.php?act=delSelect2",
                type: "POST",
                data: {
                    "str": str
                },
                dataType: "json",
                success: function(result) {
                    if (result.code == 0) {
                        window.location.reload();
                    }
                },
                error: function(data) {
                    layer.msg('服务器错误');
                    return false;
                }
            });
        })
    }


    $(document).ready(function() {
        $("#search_submit").click(function() {
            var kw = $("input[name='kw']").val();
            $("#search").modal('hide');
            if (kw == '') {
                listTable('start');
            } else {
                listTable('kw=' + kw);
            }
        });
    });

    $(document).ready(function() {
        listTable();
    })
</script>